<template>
	<view>
		<view class="header">
			<view class="title">我的礼品</view>
			<view class="bottonGroup">
				<view class="botton focus">全部</view>
			</view>
		</view>

		<view style="width: 100%; position: absolute;">
			<view
				style="position: absolute; top: -40rpx; position: absolute; left: 50%; width: 95%; transform: translate(-50%, -3%);">
				<scroll-view scroll-y="true" @scrolltolower="lower" :style="{height: scrollViewHeight+'px'}"
					style="position: initial; bottom: 0; left: 0; right: 0; top: 0;" lower-threshold="200">
					<view
						style="width: 100%; float: left; border-radius: 30rpx; background-color: #fff; margin-top: 20rpx"
						v-for="item in dataList">
						<view style="padding: 0rpx 25rpx">
							<view style="width: 100%; float: left; padding: 20rpx 0px;">
								<view style="background-color: #f8f8f8;font-size: 30rpx;display: inline-block;padding: 10rpx 20rpx;margin-bottom: 10rpx;border-radius: 10rpx; float: right;">
									状态：{{item.receive_status == 0 ? '未领取' : item.status == 0? '未核销' : item.status == 1 ? '已作废' : '已核销'}}
								</view>
								<view>
									<view style="border-left: 10rpx solid #F13B3D; padding-left: 20rpx; font-size: 30rpx; position: relative; left: -24rpx; margin: 10rpx 0rpx;">
										中奖编号：{{item.prize_sn}}
									</view>
									<view style="border-bottom: 1px solid #F3F3F3; margin-top: 20rpx; margin-bottom: 20rpx;"></view>
									<image :src="item.prize_image" mode="widthFix" style="width: 200rpx;"></image>
									<view style="display: flex; padding: 5rpx">
										<view style="font-size: 30rpx; color: #777777; width: 25%;">
											奖品名称
										</view>
										<view style="font-size: 30rpx; width: 75%;">
											{{item.prize_name}}
										</view>
									</view>
									<view style="display: flex; padding: 5rpx">
										<view style="font-size: 30rpx; color: #777777; width: 25%;">
											中奖时间
										</view>
										<view style="font-size: 30rpx; width: 75%; color: #F25454;">
											{{item.create_time}}
										</view>
									</view>
									<view style="border-bottom: 1px solid #F3F3F3; margin-top: 20rpx; margin-bottom: 20rpx;" v-if="item.receive_status == 1 && item.status == 0"></view>
									<button style="width: 200rpx; float: right; background-color: #F13B3D; color: #FFFFFF; font-size: 24rpx; border-radius: 40rpx; border: 0;" v-if="item.receive_status == 1 && item.status == 0" @click="qrcodePop(item.id)">
										我要核销
									</button>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		
		<!-- 核销码展示 -->
		<view class="qrcodePop" @click="qrcodePopReceive" v-if="showQrcodePop">
			<view class="image_row">
				<image mode="widthFix" style="width: 100%;" :src="qrcodeUrl"></image>
				<image class="close" src="/static/close.png" @click="qrcodePopReceive"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import * as api from '@/api/user'
	import storage from '@/utils/storage'
	import config from '@/config'
	export default {
		components: {},
		data() {
			return {
				showQrcodePop: false,
				qrcodeUrl: '',
				scrollViewHeight: '',
				dataList: [],
				page: 1,
				limit: 10
			}
		},
		onReady() {
			// 计算 scrollview 高度
			this.scrollViewHeight = uni.getSystemInfoSync().windowHeight - 40 - uni.getMenuButtonBoundingClientRect().top
		},
		onLoad() {
			this.getInfo();
		},
		methods: {
			lower: function(e) {
				this.page = this.page + 1;
				this.getInfo();
			},
			getInfo: function() {
				api.myActivityPrize({
					activityId: storage.get('activityId'),
					page: this.page,
					limit: this.limit
				}).then(res => {
					this.dataList = this.dataList.concat(res.data);
				})
			},
			qrcodePop: function(prizeId) {
				this.showQrcodePop = true;
				// 获取核销二维码
				this.qrcodeUrl = config.apiUrl + 'activity/wxappQrcode' + 
					'?page=pages/staff/api/confirmPrize' +
					'&scene=' + 'type=1' + '%26prizeId=' + prizeId
			},
			qrcodePopReceive: function() {
				this.showQrcodePop = false;
			}
		},
		mounted() {

		}
	}
</script>

<style>
	button::after {
	    border: none;
	}
	
	page {
		background-color: #F6F7FB;
	}

	.header {
		background-color: #F13B3D;
		position: inherit;
		width: 100%;
		height: 250rpx;
		border-radius: 0rpx 0rpx 20rpx 20rpx;
	}

	.header > .title {
		color: #fff;
		padding: 30rpx;
		font-size: 40rpx;
		font-weight: bold;
	}

	.header > .bottonGroup {
		width: 100%;
		position: initial;
		display: inline-table;
		text-align: center;
		margin-top: 0px;
	}

	.header > .bottonGroup view {
		font-size: 28rpx;
		float: left;
		padding: 5px 10px;
		margin-right: 5px;
		margin: 0px 0px 10px 10px;
		z-index: 999;
	}

	.header > .bottonGroup .botton {
		color: #FFFFFF;
	}

	.header > .bottonGroup .focus {
		border-bottom: 3px solid #FFFFFF;
		color: #FFFFFF;
	}
	
	/* 店员码展示 */
	.qrcodePop {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 1000;
	}
	
	.qrcodePop > .image_row {
		position: fixed;
		top: 50%;
		left: 50%;
		-webkit-transform: translate(-50%, -50%);
		transform: translate(-50%, -50%);
		width: 80%;
	}
	
	/* 悬浮关闭按钮 */
	.close {
		top: -90rpx;
		width: 50rpx;
		height: 50rpx;
		position: fixed;
		transform: translate(-50%, 30%);
	}
</style>